package com.fraud.dao;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.fraud.model.entity.EventLog;

@Stateless
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public class EventLogDao {

	@PersistenceContext
	EntityManager entityManager;

	public void log(EventLog joblog) {
		 entityManager.persist(joblog);
	}

	public List<EventLog> raporGetir(Date startDate, Date endDate) {

		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

		return entityManager
				.createNativeQuery(
						"select * from eventlog where to_char(baslangictarih,'YYYY-MM-DD')>:sd and to_char(baslangictarih,'YYYY-MM-DD')<:bd ",
						EventLog.class)
				.setParameter("sd", formatter.format(startDate))
				.setParameter("bd", formatter.format(endDate)).getResultList();
	}

}
